public class p1019_1_141ms {

	static//
	// -----
	// -----
	public class Main {
		public static void main(String[] args) throws Exception {
			java.util.Scanner in = new java.util.Scanner(System.in);
			int n = in.nextInt();
			for (int i = 0; i < n; i++)
				System.out.println(getDigit(in.nextInt() - 1));
		}

		// get from: 1 12 123 ... | i from 0
		static int getDigit(int i) {
			int secLength = 1, lastNum = 1, numLength = 1, nextExpendNumber = 10;
			while (i >= secLength) {
				i -= secLength;
				lastNum++;
				if (lastNum == nextExpendNumber) {
					numLength++;
					nextExpendNumber *= 10;
				}
				secLength += numLength;
			}
			return getDigit2(i);
		}

		// get from: 1234... | i from 0
		static int getDigit2(int i) {
			int secLength = 9, numLength = 1, maxNum = 9, lastMaxNum = 0;
			while (i >= secLength) {
				i -= secLength;
				numLength++;
				lastMaxNum = maxNum;
				maxNum = maxNum * 10 + 9;
				secLength = (maxNum - lastMaxNum) * numLength;
			}

			int num = lastMaxNum + 1 + i / numLength;
			num /= Math.pow(10, numLength - 1 - i % numLength);
			return num % 10;
		}
	}

	// -----
	// -----

	public static void main(String[] args) throws Exception {
		Judge.run("p1019.more.txt");
	}

}
